package questionLibrary;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import questionLibrary.QuestionInfo;
import questionLibrary.SomeConstants;

public class QuestionInfoTest {

	private String[] answersWill;
	private QuestionInfo testingQuestion;

	@Before
	public void initialize() {
		String[] answers = { "first", "second", "third" };
		answersWill = answers.clone();
		testingQuestion = new QuestionInfo("question", answersWill);
	}

	@Test
	public void testInsertAndGetQuestion() {
		assertEquals("question", testingQuestion.getQuestion());
	}

	@Test
	public void testInsertAndGetAnswers() {
		String[] answersIs = testingQuestion.getAnswers();
		assertArrayEquals(answersIs, answersWill);
	}

	@Test
	public void TestGetCountOfAnswers() {
		int countOfAnswersIs = testingQuestion.getCountOfAnswers();
		assertEquals(countOfAnswersIs, 3);
	}

	@Test
	public void TestEffects() {
		testingQuestion.insertEffects(SomeConstants.BRAIN,
				SomeConstants.HEALTH, 1, 1, -5); // 1+1-5=-3
		int expectedValue = -3;
		int realValue = testingQuestion.getEffect(SomeConstants.BRAIN,
				SomeConstants.HEALTH, 0, 1, 2);
		assertEquals(expectedValue, realValue);

	}

	@Test(expected = IllegalArgumentException.class)
	public void testEffectsExceptionFirst() throws Exception {
        int unimportantParam = 0;
        int wrongParam=5;
		testingQuestion.insertEffects(wrongParam, unimportantParam, unimportantParam, unimportantParam, unimportantParam);
	}

	/**
	 * Testing wrong count of parameters in method insertEffects
	 * @throws Exception
	 */
	@Test(expected = IllegalArgumentException.class)
	public void testEffectsExceptionSecond() throws Exception {
		int unimportantParam = 0;
		testingQuestion.insertEffects(SomeConstants.BRAIN,
				SomeConstants.HEALTH, unimportantParam, unimportantParam, unimportantParam, unimportantParam, unimportantParam, unimportantParam);
	}

	/**
	 * Testing wrong number of parameter in method insertEffects getEffect
	 * @throws Exception
	 */
	@Test(expected = IllegalArgumentException.class)
	public void testGetEffectExceptionSecond() throws Exception {

		int unimportantParam = 0;
        int wrongParam=128;
		
		testingQuestion.insertEffects(SomeConstants.BRAIN,
				SomeConstants.HEALTH, unimportantParam, unimportantParam, unimportantParam);
		testingQuestion.getEffect(unimportantParam, wrongParam, unimportantParam);
	}

}
